# @shuaige : 陈世玉
# @name :003Handler处理器的基本使用.py
# @time :2024/12/3 22:39
import urllib.request
from urllib.request import HTTPHandler
url='http://www.baidu.com'
headers={
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"
}
request=urllib.request.Request(url=url,headers=headers)
#1.获取处理器对象
handler=HTTPHandler()
#2.获取opener对象
opener=urllib.request.build_opener(handler)
#3.调用open方法
response=opener.open(request)
print(response.read().decode('utf-8'))
